

var   reSourceId;
/**
 * 初始化页面
 */

$(function(){	
	easySelect2();
	initData();
	initLinkResource();	
})


function initLinkResource(){
	queryLinkResource();
}


function initData(){
	reSourceId=[];
	 for (var i = 0; i < chenckResource.length; i++) {
		 reSourceId.push(""+ chenckResource[i].resourceId);
	}
	 
}


/**查询联系人
 * @returns
 */
function queryLinkResource(){
	var linkResource= [ {code : 'resourceId',name : 'checkBox',width : 10},
                     {code : 'modelType',name : '资源类型'}, 
	                 {code : 'manageIp',name : '设备IP'}, 
	                 {code : 'resourceName',name : '名称'}, 
	                 {code : 'platform',name : '操作系统'}, 
	                 {code : 'bzName',name : '所属业务系统'}, 
	                 {code : 'modelName',name : '模型名称'},
	                ];
	var parm = {
		url : basePath + '/radar/linkGroup/getResourceList.do',
		divID : 'groupLinkResource',
		afterQuery:'afterselect'
			};
	// 常规参数
	var data = {
		'manageIp' : $("#manageIp").val(),
		'resourceName': $("#resourceName").val(),
		'classes': $("#classes").val(),
		'operate': $("#operate").val(),
		'groupId': groupId
		
	}; // 赛选

	easyQuery(linkResource, parm, data);
}



function  afterselect(){
	  for (var i = 0; i < reSourceId.length; i++) {
		  $("input[type='checkbox'][nodeId='"+reSourceId[i]+"']").prop("checked", true);
	}
}

// 保存绑定的设备
function savelinkResource(){
     var checkBox='';
	for (var i = 0; i < reSourceId.length; i++) {
		checkBox=checkBox+reSourceId[i]+',';
	}
	if(checkBox.length>0){
		checkBox=checkBox.substring(0,(checkBox.length-1));
	}

	$.ajax({
		url:basePath+"/radar/linkGroup/savelinkResource.do",
	  	type:"post",
	  	dataType:"json",
	    data:{
		    "groupId":groupId,
		    "linkResourceIds":checkBox,
       },
       success: function(result){
    	   var result = result.data;
    	   if(result.indexOf("success")==0){
    		   parent.layer.msg('保存成功！', {icon : 1,time : 2000});  		
    		   closeWindow();
    	   }else{
    		   parent.layer.msg('保存失败！',{icon : 1,time : 2000}); 
    		   closeWindow();
    	   }
       }
	});
}

/**复选框 
 * @param f
 */
function  manucheck(f){
     var id=$(f).attr("nodeId");
     if($(f).attr('checked')){
    	 reSourceId.push(id);
     }else{
    	 var index = reSourceId.indexOf(id);
    	 if (index > -1) {
    		 reSourceId.splice(index, 1);
          }
	}
}

/**复选框全选后操作
 * @param f
 */
function afterSelectAll(f){	
	 var divID=$(f).attr("divID");
	 $("input[type='checkbox'][divID='"+divID+"'][nodeId]").each(function (){
		 var index = reSourceId.indexOf($(this).attr("nodeId"));
		 if($(f).attr('checked')){
			 //判断数组中是否含有  不含有再添加			
	    	 if (index == -1) {
	    		 reSourceId.push($(this).attr("nodeId"));
	          }			
	     }else{	    	
	    	 if (index > -1) {
	    		 reSourceId.splice(index, 1);
	          }
		} 
	 });   
}
